package com.prs.crm.action.document;


import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;


import com.prs.crm.domain.document.DraftType;
import com.prs.crm.domain.document.NumberSet;
import com.prs.crm.service.document.DraftTypeService;
import com.prs.crm.service.document.NumberSetService;

public class NumberSetAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private NumberSet numberSet;
	private NumberSetService numberSetService;
	private Integer[] ids;
	private PaginationSupport pagination;
	
	private List<DraftType> draftType;
	private DraftTypeService draftTypeService;
	public String[] selectMoudle;
	public List<DraftType> getDraftType() {
		return draftType;
	}
	public void setDraftType(List<DraftType> draftType) {
		this.draftType = draftType;
	}
	public DraftTypeService getDraftTypeService() {
		return draftTypeService;
	}
	public void setDraftTypeService(DraftTypeService draftTypeService) {
		this.draftTypeService = draftTypeService;
	}
	public String[] getSelectMoudle() {
		return selectMoudle;
	}
	public void setSelectMoudle(String[] selectMoudle) {
		this.selectMoudle = selectMoudle;
	}
	public NumberSet getNumberSet() {
		return numberSet;
	}
	public void setNumberSet(NumberSet numberSet) {
		this.numberSet = numberSet;
	}
	public NumberSetService getNumberSetService() {
		return numberSetService;
	}
	public void setNumberSetService(NumberSetService numberSetService) {
		this.numberSetService = numberSetService;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	@Action("listNumberSet")
	public String listNumberSet(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(NumberSet.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getNumberSetService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("editNumberSet")
	public String editNumberSet(){
		this.draftType=this.getDraftTypeService().getAllDraftType();
		return SUCCESS;
	}
	
	@Action(value="saveNumberSet",results={
			@Result(name="success",type="redirect",location="listNumberSet"),
			@Result(name="error",type="chain",location="editNumberSet")
	})
	public String saveNumberSet(){
		this.getNumberSetService().save(numberSet);
		return SUCCESS;
	}
	
	@Action(value="removeNumberSet",results={
			@Result(name="success",type="redirect",location="listNumberSet"),
			@Result(name="error",type="chain",location="listNumberSet")
	})
	public String removeNumberSet(){
		if (ids==null) {
			this.setPrompt("请选择一行！");
			return ERROR;
		}
		this.getNumberSetService().batchRemove(ids);
		return SUCCESS;
	}
}
